import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
from Config import img_path

#img = cv.imread(img_path)
img = cv.imdecode(np.fromfile('F:\\剪切gu\\4908523_02.jpg', dtype=np.uint8), -1)
assert img is not None, "file could not be read, check with os.path.exists()"
rows,cols,ch = img.shape
print(rows,cols)
pts1 = np.float32([[1568,58],[1568,1966],[2698,58],[2698,1966]])
pts2 = np.float32([[0,0],[0,1905],[1131,0],[1131,1905]])
M = cv.getPerspectiveTransform(pts1,pts2)
dst = cv.warpPerspective(img,M,(1131,1905))
plt.subplot(122),plt.imshow(img),plt.title('Input')
plt.subplot(121),plt.imshow(dst),plt.title('Output')
plt.show()
cv.imwrite('3.png', dst)